# This will be configure file for p4 server,
# and it need be $USERHOME/$P4SERVERNAME.ini
USER=perforce
USERHOME=/local/perforce

P4USER=perforce
P4PASSWD=123
P4SERVERNAME=p4server001

p4=$USERHOME/p4
p4d=$USERHOME/p4d

P4PORT=10.148.151.98:1666
P4ROOT=$USERHOME/p4root
JOURNAL=$USERHOME/journal/journal
LOG=$USERHOME/log/p4server001.log

TRACKLEVEL=1
SERVERLEVEL=2


#!/bin/bash
#
# chkconfig:1235 80 80
# description: p4server001 daemon
#

PATH=/sbin:/bin:/usr/bin:/usr/sbin

# Source in the configs...
. /local/perforce/p4server001.ini

SU="su $USER -c"
LOCKFILE=$USERHOME/$P4SERVERNAME.lock

start() {
    STARTCMD="$p4d -d -v server=$SERVERLEVEL,track=$TRACKLEVEL -p $P4PORT -r $P4ROOT -L $LOG -J $JOURNAL"
    $SU "$STARTCMD" 2>&1
    touch $LOCKFILE
    $SU "logger p4d starting"
    echo "p4d was started on" `hostname -s`
}

stop() {
    STOPCMD="$p4 -p $P4PORT -u $P4USER admin stop"
    echo $P4PASSWD | $p4 -p $P4PORT -u $P4USER login
    $SU "$STOPCMD" 2>&1
    rm $LOCKFILE
    $SU "logger p4d stopping"
    echo "p4d was stopped on" `hostname -s`
}

status() {
    if [ -f $LOCKFILE ];
        then
            echo p4d status: running
        else
            echo p4d status: stopped
    fi
}

case "$1" in

'start')
        start
        ;;

'stop')
        stop
        ;;

'status')
        status
        ;;
*)
        echo "Usage: p4server001 { start | stop | status }"
        ;;

esac


